#include "TextConverter.h"
#include "iconv.h"
#include <cocos2d.h>

std::string TextConverter::MudLocalStringToUtf8(const std::string& src)
{
	iconv_t cd = iconv_open("UTF-8", "BIG5");
	const char* buff_big5 = src.c_str();
	size_t big5_len = src.length();
	size_t utf8_len = big5_len * 2;
	char* buff_utf8 = new char[utf8_len];
	memset(buff_utf8, 0, utf8_len);
	char* buff_out = buff_utf8;
	size_t ret_conv = iconv(cd, &buff_big5, &big5_len, &buff_out, &utf8_len);
	cocos2d::log("ret_conv = %d, %X, %X, %X, %X", (int)ret_conv, buff_utf8[0], buff_utf8[1], buff_utf8[2], buff_utf8[3]);
	std::string str_utf8 = std::string(buff_utf8);
	iconv_close(cd);
	delete[] buff_utf8;

	return str_utf8;
}